﻿using Susha.Models;
using Susha.Models.Helpers;
using Susha.Models.Pages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Susha.Areas.Admin.Controllers
{
    public class NewsController : Controller
    {
        //
        // GET: /Admin/News/

        [HttpGet]
        public ActionResult Index()
        {
            NewsPage page = new NewsPage();
            return View(page);
        }

        [HttpPost]
        public ActionResult Index(News news)
        {
            news.SmallText = news.Text.Remove(256);

            using (ImageTools iTools = new ImageTools(news.OriginalPhoto))
            {
                news.BigPhoto = iTools.SaveFile(PagesEnum.News, 700, 432);
                news.SmallPhoto = iTools.SaveFile(PagesEnum.News, 220, 135);
            }

            NewsRepository.Save(news);

            return RedirectToAction("Index");
        }
    }
}
